<?php

namespace IDock\Insurance\TAIC\Request;

use IDock\Http\Request;
use IDock\Http\RequestFormat;
use IDock\Http\RequestMethod;

class AllTAICRequest extends Request
{

    protected $method = RequestMethod::POST;

    protected $format = RequestFormat::RAW;

    protected $tradeNo = '';

    public function loadConfig(array $config): Request
    {
        $this->gateway = $config['gateway'] ?? '';

        $this->logsDir = $config['logsDir'] ?? '';

        $this->timeout = $config['timeout'] ?? '';

        $this->proxy = $config['proxy'] ?? '';

        $this->proxyPW = $config['proxyPW'] ?? '';

        $this->proxyAccount = $config['proxyAccount'] ?? '';

        return $this;
    }

    public function getTradeNo()
    {
        return $this->tradeNo;
    }

    public function setTradeNo()
    {
        $this->tradeNo = date('YmdHis') . rand(10000, 99999);
    }

    public function responseLogs($uuid, $data)
    {
        if (json_decode($data, true)) {
            $data = json_encode(json_decode($data, true), JSON_UNESCAPED_UNICODE);
        }
        parent::responseLogs($uuid, $data);
    }
}
